import { DirectionCode, FingerStyle, KeyEventParameters, SceneUtils } from "../../SceneControl";
import HandGridMoveScene from "../HandGridMoveScene";

const { ccclass, property } = cc._decorator;

@ccclass
export default class BattleDescScene extends HandGridMoveScene {
    txtName: cc.Label;

    protected onEnable(): void {
        this.onlyGrid = true;
        this.txtName = cc.find("frame/txtName", this.node).getComponent(cc.Label);
        super.onEnable();
        this.startScene();

        if (this.txtName.string == "交换") {
            this.doFunc = this.onChange;
            this.tscene.fingerStyle = FingerStyle.hand;
        } else if (this.txtName.string == "铲除") {
            this.doFunc = this.onRemove;
            this.tscene.fingerStyle = FingerStyle.finger;
        }
        this.onBack = cc.find("btnClose", this.node);
    }

    doFunc: () => void;

    protected addBtnEventKeyDown(para: KeyEventParameters): void {
        if (para.DirectionCode === DirectionCode.ENTER) {
            this.doFunc();
        }
    }

    protected resetBtnPos(offset?: cc.Vec3): void {
        if (this.txtName.string == "交换") {
            super.resetBtnPos(offset);
            this.tscene.fingerStyle = FingerStyle.hand;
        } else {
            super.resetBtnPos(cc.v3(0, 0));
            this.tscene.fingerStyle = FingerStyle.finger;
        }
    }


    onRemove() {
        let item = this.grids[this.currSite.x][this.currSite.y];
        if (item.enabled) {
            SceneUtils.emitButton(item._view);
        }
    }

    onChange() {
        let item = this.grids[this.currSite.x][this.currSite.y];
        if (item.enabled) {
            this.catchNode = item._view;
        }
    }

}
